package com.uk.ui.kontrata;

import java.util.List;

import com.uk.data.containers.KontrataContainer;
import com.uk.data.entities.Fatura;
import com.uk.data.entities.Kontrata;
import com.uk.reports.ReportWindow;
import com.uk.reports.Reports;
import com.uk.ui.ColumnGeneratorUtils;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;

public class KontrataDebitorListView extends VerticalLayout{

	Table kontrataTable = new Table();
	private final Button printListButton = new Button("Printo liste");
	
	public KontrataDebitorListView(KontrataPanel kontrataPanel) {
		super();
		final List<Kontrata> kontrataList = kontrataPanel.getFaturaBean().listDebitor();
		for (Kontrata kontrata : kontrataList) {
			
			
			kontrata.setFaturaPapaguarNeTotal(kontrataPanel.getFaturaBean().queryFaturainTotal(kontrata, false));
			
		}
		
		kontrataTable.setContainerDataSource(new KontrataContainer(kontrataList));
		kontrataTable.setVisibleColumns(new Object[]{"id","emri","mbiemri","adresa","perdorimi", "faturaPapaguarNeTotal"});
		kontrataTable.setColumnHeaders(new String[]{"ID", "EMRI", "MBIEMRI", "ADRESA", "PERDORIMI", "FATURA PAPAGUAR"});
		kontrataTable.addGeneratedColumn("perdorimi", ColumnGeneratorUtils.perdorimiColumnGenerator());
		kontrataTable.setPageLength(10);
		this.addComponent(kontrataTable);
		this.setSizeFull();
		this.kontrataTable.setSizeFull();
		this.addComponent(printListButton);
		this.setComponentAlignment(printListButton, Alignment.TOP_RIGHT);
		
		this.printListButton.addListener(new Button.ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				getApplication().getMainWindow().addWindow(new ReportWindow(getApplication(), Reports.buildDebitorReport(kontrataList))) ;
				
			}
		});
		
	}

	
	
	
}
